<!-- 选择列表 -->
<script lang="ts" setup>
import type { PropType } from 'vue'
import type { IMyPick } from '@/types/global'

const props = defineProps({
  pickList: {
    type: Array as PropType<IMyPick[]>,
    default() {
      return []
    }
  }
})

/**
 * 清空所选数据
 */
function clearAllClick() {
  props.pickList.splice(0)
}
/**
 * 删除指定所选数据
 */
function delPickClick(index: number) {
  props.pickList.splice(index, 1)
}
</script>

<template>
  <div class="dui-dialog-pick-bg">
    <div class="dui-dialog-pick-header">
      <div class="dui-dialog-pick-header-title">共选择 {{ pickList.length }} 条数据</div>
      <el-button type="danger" plain size="small" @click="clearAllClick">清空</el-button>
    </div>
    <div class="dui-dialog-pick-list">
      <template v-for="(pItem, pIndex) in pickList || []" :key="pItem.id">
        <div class="dui-dialog-pick-list-item">
          <div class="dui-dialog-pick-list-item-title">{{ pItem.name }}</div>
          <el-button type="danger" link @click="delPickClick(pIndex)">删除</el-button>
        </div>
      </template>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.dui-dialog-pick-bg {
  height: 100%;
  border: 1px solid lightgray;
  overflow: hidden;

  .dui-dialog-pick-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 35px;
    background-color: #f7f7f7;
    padding: 0 10px;
  }
  .dui-dialog-pick-header-title {
    font-weight: bold;
    width: calc(100% - 60px);
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
  .dui-dialog-pick-list {
    height: calc(100% - 35px);
    overflow-y: auto;
    .dui-dialog-pick-list-item {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 5px 10px;
      box-sizing: border-box;
      height: 35px;
      border-bottom: 1px solid lightgray;
      .dui-dialog-pick-list-item-title {
        width: calc(100% - 50px);
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
      }
    }
  }
}
</style>
